
<!DOCTYPE html>
<html lang="">


<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
  <meta name="theme-color" content="#202020"/>
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <script src="/js/busuanzi.pure.mini.js" async></script>
  
  
    <meta name="keywords" content="Emberjs," />
  

  
    <meta name="description" content="一个专注一coding的网站。提供丰富编程知识，包括Spring、Java、EmberJS、SpringBoot等等技术。" />
  
  
  <link rel="icon" type="image/x-icon" href="/image/favicon.ico">
  <title>emberjs常见错误集 [ Keep Coding ]</title>
  
    <!-- stylesheets list from config.yml -->
    
      <link rel="stylesheet" href="/css/pure-min.css">
    
      <link rel="stylesheet" href="/css/xoxo.css">
    
  
<meta name="generator" content="Hexo 5.0.2"><link rel="alternate" href="/atom.xml" title="Keep Coding" type="application/atom+xml">
</head>

<body>
  <div class="nav-container">
    <nav class="home-menu pure-menu pure-menu-horizontal">
  <a class="pure-menu-heading" href="/">
    <img class="avatar" src="/image/favicon.ico">
    <span class="title">Keep Coding</span>
  </a>

  <ul class="pure-menu-list clearfix">
      
          
            <li class="pure-menu-item"><a href="/" class="pure-menu-link">首页</a></li>
          
      
          
            <li class="pure-menu-item"><a href="/archives" class="pure-menu-link">归档</a></li>
          
      
          
            <li class="pure-menu-item"><a href="/tags" class="pure-menu-link">标签</a></li>
          
      
          
            <li class="pure-menu-item"><a href="/search" class="pure-menu-link">搜索</a></li>
          
      
          
            <li class="pure-menu-item"><a href="/about" class="pure-menu-link">关于</a></li>
          
      
          
            <li class="pure-menu-item"><a href="/atom.xml" class="pure-menu-link">订阅</a></li>
          
      
  </ul>
   
</nav>
  </div>

  <div class="container" id="content-outer">
    <div class="inner" id="content-inner">
      <div class="post-container">
  <article class="post" id="post">
    <header class="post-header text-center">
      <h1 class="title">
        emberjs常见错误集
      </h1>
      <span>
        
        <time class="time" datetime="2020-01-18T14:50:37.000Z">
        2020-01-18
      </time>
        
      </span>
      <span class="slash">/</span>
      <span class="post-meta">
      <span class="post-tags">
        <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Emberjs/" rel="tag">Emberjs</a></li></ul>
      </span>
    </span>
      <span class="slash">/</span>
      <span class="read">
      <span id="busuanzi_value_page_pv"></span> 点击
    </span>
      <span class="slash">/</span>
      <span class="read">阅读耗时 2 分钟</span>
    </header>

    <div class="post-content">
      <p><strong>独乐乐不如众乐乐。</strong></p>
<p>你踩的坑很可能后来者也回踩！拯救菜鸟人人有着！！</p>
<p>本篇为<code>Ember.js</code>开发者汇总常见问题，比如浏览器兼容性问题、组件使用等。大部分内容都摘了于<a target="_blank" rel="noopener" href="http://stackoverflow.com/search?q=ember.js"><code>stackoverflow</code></a>和<a target="_blank" rel="noopener" href="http://discuss.emberjs.com/"><code>emberjs discuss</code></a>。</p>
<p><strong>1. 浏览器兼容性支持</strong></p>
<p><a target="_blank" rel="noopener" href="http://stackoverflow.com/questions/9873744/ember-js-browser-support">emberjs browser support</a></p>
<p><strong>2. 部署服务器后刷新出现404问题</strong></p>
<p>如果你的项目使用命令<code>ember build --prod</code>打包后部署到服务器上，进入首页没问题，并且在首页刷新也没问题。但是进入某个子路由后再刷新页面就会出现<code>404</code>错误。但是这个错误在开发环境却没有任何问题。这是由于服务器设置的问题。以nginx为例。只需要修改：<code>nginx/conf/vhosts/default.conf</code>即可_配置文件路由要根据自己nginx路径为准_。在此配置文件中加入如下内容：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">location &#x2F; &#123;</span><br><span class="line">        rewrite ^ &#x2F;index.html break;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    location &#x2F;assets&#x2F; &#123;</span><br><span class="line">        # do nothing and let nginx handle this as usual</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<p>参考网址：<a target="_blank" rel="noopener" href="http://discuss.emberjs.com/t/how-to-serve-all-routes-on-a-production-server-exactly/6372/2">http://discuss.emberjs.com/t/how-to-serve-all-routes-on-a-production-server-exactly/6372/2</a></p>
<p>还有另外一种更加简单的解决办法：直接在<code>router.js</code>设置<code>location</code>属性为<code>hash</code>即可。更多解释请看官网教程<a target="_blank" rel="noopener" href="http://emberjs.com/api/modules/ember-routing.html">EMBER-ROUTING MODULE</a></p>
<p><strong>3. 如何修改使用命令<code>ember build --prod</code>打包后的静态文件的名字，每个名字中会自动生成一个hash值一个类似于md5加密后的密文。</strong></p>
<p><strong>4. 项目安装出错，报错信息为无法访问github</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">Error creating new application. Removing generated directory `./super-rentals`</span><br><span class="line">Failed to execute <span class="string">&quot;git ls-remote --tags --heads https://github.com/ember-cli/ember-cli-shims.git&quot;</span>, <span class="built_in">exit</span> code of <span class="comment">#128</span></span><br><span class="line">fatal: unable to access <span class="string">&#x27;https://github.com/ember-cli/ember-cli-shims.git/&#x27;</span>: Failed to connect to github.com port 443: Connection refus</span><br><span class="line">ed</span><br><span class="line"></span><br><span class="line">Error: Failed to execute <span class="string">&quot;git ls-remote --tags --heads https://github.com/ember-cli/ember-cli-shims.git&quot;</span>, <span class="built_in">exit</span> code of <span class="comment">#128</span></span><br><span class="line">fatal: unable to access <span class="string">&#x27;https://github.com/ember-cli/ember-cli-shims.git/&#x27;</span>: Failed to connect to github.com port 443: Connection refus</span><br><span class="line">ed</span><br><span class="line"></span><br><span class="line">    at createError (D:\Program Files\nodejs\node_global\node_modules\ember-cli\node_modules\bower\lib\util\createError.js:4:15)</span><br><span class="line">    at ChildProcess.&lt;anonymous&gt; (D:\Program Files\nodejs\node_global\node_modules\ember-cli\node_modules\bower\lib\util\cmd.js:102:21)</span><br><span class="line">    at emitTwo (events.js:87:13)</span><br><span class="line">    at ChildProcess.emit (events.js:172:7)</span><br><span class="line">    at maybeClose (internal[擦汗]ild_process.js:827:16)</span><br><span class="line">    at Process.ChildProcess._handle.onexit (internal[擦汗]ild_process.js:211:5)</span><br></pre></td></tr></table></figure>
<p>解决办法：直接从github下载缺失的依赖包，比如上述错误是缺少<code>ember-cli-shims</code>，可以尝试直接从<code>https://github.com/ember-cli/ember-cli-shims.git</code>下载，然后复制到<code>bower_components</code>目录之下。</p>
<p><strong>5. 项目启动出现’import’ is only available in ES6 (use ‘eversion: 6’)错误</strong></p>
<p>错误详细请看下图：</p>
<p><img src="http://blog.ddlisting.com/content/images/2016/08/1.png" alt="&#39;import&#39; is only available in ES6 (use &#39;eversion: 6&#39;)"></p>
<p>解决办法：</p>
<ol>
<li>项目下缺少文件<code>.jshintrc</code>，可以从其他ember项目直接复制过来</li>
<li>重新安装项目依赖，安装命令：<code>npm install</code>和<code>bower install</code></li>
</ol>
<p>然后重启项目即可。</p>
<p>参考网址：<a target="_blank" rel="noopener" href="https://github.com/ember-cli/ember-cli/issues/1418">https://github.com/ember-cli/ember-cli/issues/1418</a></p>
<p><strong>欢迎补充</strong></p>

    </div>

      
    <div class="post-nav">
      <div class="post-nav-item post-nav-next">
        
          <span>〈 </span>
          <a href="/2020/01/18/fq/%E5%BC%BA%E5%88%B6%20Google.com%20%E5%9F%9F%E5%90%8D%E4%BD%BF%E7%94%A8%20HTTPS%EF%BC%88SSL%EF%BC%89/" rel="next" title="强制 Google.com 域名使用 HTTPS（SSL）">
          强制 Google.com 域名使用 HTTPS（SSL）
          </a>
        
      </div>
  
      <div class="post-nav-item post-nav-prev">
          
          <a href="/2020/01/18/ember-teach/ember.js%E6%9C%80%E5%B8%B8%E7%94%A8%E7%9A%84addon/" rel="prev" title="addon收集">
            addon收集
          </a>
          <span>〉</span>
        
      </div>
    </div>
  
  </article>
  <div class="toc-container">
    

  </div>
</div>


<div class="copyright">
    <span>本作品采用</span>
    <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by/4.0/">知识共享署名 4.0 国际许可协议</a>
    <span>进行许可。 转载时请注明原文链接。</span>
</div>
<div class="share">

</div>
<div class="post-container">
    <article class="post">
      <div id="container"></div>
    </article>
</div>

<link rel="stylesheet" href="https://imsun.github.io/gitment/style/default.css">
<script src="https://imsun.github.io/gitment/dist/gitment.browser.js"></script>
<script>
var gitment = new Gitment({
  id: 'emberjs常见错误集', // 可选。默认为 location.href
  owner: 'ubuntuvim',
  repo: 'ubuntuvim.github.io',
  oauth: {
    client_id: '48b3df0bf4ba1743e0a3',
    client_secret: 'c6c2cec09acb5eecc9d325d56cef187264aa1e16',
  },
})
gitment.render('container')
</script>



    </div>

    

  </div>
  <footer class="footer text-center">
    <div id="bottom-inner">
        <a class="bottom-item" href="http://xcoding.tech/">首页</a> |
        <a class="bottom-item" href="http://xcoding.tech/" target="_blank">主站</a> |
        <a class="bottom-item" href="https://github.com/ubuntuvim" target="_blank">GitHub</a> |
        <a class="bottom-item" href="https://hexo.io" target="_blank">Powered by hexo</a> |
        <a class="bottom-item" href="https://github.com/KevinOfNeu/hexo-theme-xoxo" target="_blank">Theme xoxo</a>
    </div>
</footer>


  <script src='https://unpkg.com/mermaid@7.1.2/dist/mermaid.min.js'></script>
  <script>
    if (window.mermaid) {
      mermaid.initialize({theme: 'forest'});
    }
  </script>


  
  <!-- scripts list from theme config.yml -->
  
    <script src="/js/zepto.min.js"></script>
  


<script>
  (function(window, document, undefined) {

    var timer = null;

    function returnTop() {
      cancelAnimationFrame(timer);
      timer = requestAnimationFrame(function fn() {
        var oTop = document.body.scrollTop || document.documentElement.scrollTop;
        if (oTop > 0) {
          document.body.scrollTop = document.documentElement.scrollTop = oTop - 50;
          timer = requestAnimationFrame(fn);
        } else {
          cancelAnimationFrame(timer);
        }
      });
    }

    var hearts = [];
    window.requestAnimationFrame = (function() {
      return window.requestAnimationFrame ||
        window.webkitRequestAnimationFrame ||
        window.mozRequestAnimationFrame ||
        window.oRequestAnimationFrame ||
        window.msRequestAnimationFrame ||
        function(callback) {
          setTimeout(callback, 1000 / 60);
        }
    })();
    init();

    function init() {
      css(".heart{z-index:9999;width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: absolute;}.heart:after{top: -5px;}.heart:before{left: -5px;}");
      attachEvent();
      gameloop();
      addMenuEvent();
    }

    function gameloop() {
      for (var i = 0; i < hearts.length; i++) {
        if (hearts[i].alpha <= 0) {
          document.body.removeChild(hearts[i].el);
          hearts.splice(i, 1);
          continue;
        }
        hearts[i].y--;
        hearts[i].scale += 0.004;
        hearts[i].alpha -= 0.013;
        hearts[i].el.style.cssText = "left:" + hearts[i].x + "px;top:" + hearts[i].y + "px;opacity:" + hearts[i].alpha + ";transform:scale(" + hearts[i].scale + "," + hearts[i].scale + ") rotate(45deg);background:" + hearts[i].color;
      }
      requestAnimationFrame(gameloop);
    }

    /**
     * 给logo设置点击事件
     * 
     * - 回到顶部
     * - 出现爱心
     */
    function attachEvent() {
      var old = typeof window.onclick === "function" && window.onclick;
      var logo = document.getElementById("logo");
      if (logo) {
        logo.onclick = function(event) {
          returnTop();
          old && old();
          createHeart(event);
        }
      }
      
    }

    function createHeart(event) {
      var d = document.createElement("div");
      d.className = "heart";
      hearts.push({
        el: d,
        x: event.clientX - 5,
        y: event.clientY - 5,
        scale: 1,
        alpha: 1,
        color: randomColor()
      });
      document.body.appendChild(d);
    }

    function css(css) {
      var style = document.createElement("style");
      style.type = "text/css";
      try {
        style.appendChild(document.createTextNode(css));
      } catch (ex) {
        style.styleSheet.cssText = css;
      }
      document.getElementsByTagName('head')[0].appendChild(style);
    }

    function randomColor() {
      // return "rgb(" + (~~(Math.random() * 255)) + "," + (~~(Math.random() * 255)) + "," + (~~(Math.random() * 255)) + ")";
      return "#F44336";
    }

    function addMenuEvent() {
      var menu = document.getElementById('menu-main-post');
      if (menu) {
        var toc = document.getElementById('toc');
        if (toc) {
          menu.onclick = function() {
            if (toc) {
              if (toc.style.display == 'block') {
                toc.style.display = 'none';
              } else {
                toc.style.display = 'block';
              }
            }
          };
        } else {
          menu.style.display = 'none';
        }
      }
    }

  })(window, document);
</script>

  



</body>
</html>
